package com.Ling.Thread.singleton;

/**
 * File Name: SingletonThread
 * Date: 2020-06-28 10:45
 * Author: liangling
 * Description 多线程实现单例模式
 */
public class SingletonThread {
    public static void main(String[] args) {

        Runnable runnable = ()->{
            Boss.getBoss();
        };
        for(int i=0;i<100;i++){
            new Thread(runnable).start();
    }

    }
}

class Boss{
    private  Boss(){
        System.out.println("一个Boss对象被实例化");
    }

    private static Boss Instance = null;
//    public  static Boss getBoss(){
////        synchronized (""){
////            if (null == Instance){
////                Instance = new Boss();
////            }
////        }
////
////
////        return Instance;
////    }

    public static synchronized Boss getBoss(){

        if (Instance == null){
           Instance = new Boss();
        }
        return Instance;
    }
}